package com.sdhs.web.controller.contract;

import com.sdhs.common.annotation.Log;
import com.sdhs.common.core.controller.BaseController;
import com.sdhs.common.core.domain.AjaxResult;
import com.sdhs.common.core.page.TableDataInfo;
import com.sdhs.common.enums.BusinessType;
import com.sdhs.common.utils.poi.ExcelUtil;
import com.sdhs.system.domain.GcContractMiddle;
import com.sdhs.system.service.IGcContractMiddleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 合同中间表Controller
 *
 * @author add
 * @date 2025-04-04
 */
@RestController
@RequestMapping("/system/middle")
public class GcContractMiddleController extends BaseController
{
    @Autowired
    private IGcContractMiddleService gcContractMiddleService;

    /**
     * 查询合同中间表列表
     */
    @PreAuthorize("@ss.hasPermi('system:middle:list')")
    @GetMapping("/list")
    public TableDataInfo list(GcContractMiddle gcContractMiddle)
    {
        startPage();
        List<GcContractMiddle> list = gcContractMiddleService.selectGcContractMiddleList(gcContractMiddle);
        return getDataTable(list);
    }

    /**
     * 导出合同中间表列表
     */
    @PreAuthorize("@ss.hasPermi('system:middle:export')")
    @Log(title = "合同中间表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GcContractMiddle gcContractMiddle)
    {
        List<GcContractMiddle> list = gcContractMiddleService.selectGcContractMiddleList(gcContractMiddle);
        ExcelUtil<GcContractMiddle> util = new ExcelUtil<GcContractMiddle>(GcContractMiddle.class);
        util.exportExcel(response, list, "合同中间表数据");
    }

    /**
     * 获取合同中间表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:middle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gcContractMiddleService.selectGcContractMiddleById(id));
    }

    /**
     * 新增合同中间表
     */
    @PreAuthorize("@ss.hasPermi('system:middle:add')")
    @Log(title = "合同中间表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GcContractMiddle gcContractMiddle)
    {
        return toAjax(gcContractMiddleService.insertGcContractMiddle(gcContractMiddle));
    }

    /**
     * 修改合同中间表
     */
    @PreAuthorize("@ss.hasPermi('system:middle:edit')")
    @Log(title = "合同中间表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GcContractMiddle gcContractMiddle)
    {
        return toAjax(gcContractMiddleService.updateGcContractMiddle(gcContractMiddle));
    }

    /**
     * 删除合同中间表
     */
    @PreAuthorize("@ss.hasPermi('system:middle:remove')")
    @Log(title = "合同中间表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gcContractMiddleService.deleteGcContractMiddleByIds(ids));
    }
}
